﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace tdgame
{
    public class BasicShader : Effect, IEffectMatrices
    {
        private EffectParameter projectionParameter;
        private EffectParameter viewParameter;
        private EffectParameter worldParameter;
        private EffectParameter shaderIndexParameter;
        private EffectParameter uvScaleParameter;
        private EffectParameter diffuseColorParameter;
        public BasicShader(ContentManager content)
            : base(content.Load<Effect>("DeferredRender"))
        {
            this.initParams();
        }

        private void initParams()
        {
            this.projectionParameter = base.Parameters["Projection"];
            this.viewParameter = base.Parameters["View"];
            this.worldParameter = base.Parameters["World"];
            this.shaderIndexParameter = base.Parameters["shaderIndex"];
            this.uvScaleParameter = base.Parameters["uv_scale"];
            this.diffuseColorParameter = base.Parameters["diffuseColor"];
        }

        public Vector3 DiffuseColor
        {
            get { return this.diffuseColorParameter.GetValueVector3(); }
            set { this.diffuseColorParameter.SetValue(value); }
        }

        public bool UseTexture
        {
            get { return this.shaderIndexParameter.GetValueInt32() == 0; }
            set { this.shaderIndexParameter.SetValue(value ? 0 : 1); }
        }

        public Vector2 UvScale
        {
            get { return this.uvScaleParameter.GetValueVector2(); }
            set { this.uvScaleParameter.SetValue(value); }
        }

        public Microsoft.Xna.Framework.Matrix Projection
        {
            get
            {
                return this.projectionParameter.GetValueMatrix();
            }
            set
            {
                this.projectionParameter.SetValue(value);
            }
        }

        public Microsoft.Xna.Framework.Matrix View
        {
            get
            {
                return this.viewParameter.GetValueMatrix();
            }
            set
            {
                this.viewParameter.SetValue(value);
            }
        }

        public Microsoft.Xna.Framework.Matrix World
        {
            get
            {
                return this.worldParameter.GetValueMatrix();
            }
            set
            {
                this.worldParameter.SetValue(value);
            }
        }
    }
}
